/*
 * Copyright (c) 2018, apexes.net. All rights reserved.
 *
 *         http://www.apexes.net
 *
 */
package net.apexes.fqueue.demo;

import net.apexes.fqueue.FQueue;

/**
 * @author <a href=mailto:hedyn@foxmail.com>HeDYn</a>
 */
public class FQueueDemo {

    public static void main(String[] args) throws Exception {
        FQueue queue = new FQueue(".temp/test-fqueue");

        queue.offer("aaa".getBytes());
        assert queue.size() == 1;

        byte[] bytes = queue.peek();
        print("peek1", queue.size(), bytes);

        bytes = queue.remove();
        print("remove", queue.size(), bytes);

        bytes = queue.peek();
        print("peek2", queue.size(), bytes);

        queue.offer("bbb".getBytes());

        bytes = queue.poll();
        print("poll1", queue.size(), bytes);

        bytes = queue.poll();
        print("poll2", queue.size(), bytes);
    }

    private static void print(String name, int size, byte[] bytes) {
        if (bytes != null) {
            System.out.println(name + " : " + size + " : " + new String(bytes));
        } else {
            System.out.println(name + " : " + size + " : null");
        }
    }
}
